<?php
/**
 * Created by 七月
 * User: 七月
 * Date: 2017/2/15
 * Time: 13:40
 */

namespace app\api\controller\v1;


use app\BaseController;
use app\api\validate\IDMustBePositiveIntValidate;

use app\api\model\BannerModel;
use app\api\exception\MissException;

/**
 * Banner资源
 */
class BannerController extends BaseController
{
//    protected $beforeActionList = [
//        'checkPrimaryScope' => ['only' => 'getBanner']
//    ];

    /**
     * 获取Banner信息
     * @url     /banner/:id
     * @http    get
     * @param int $id banner id
     * @return  array of banner item , code 200
     * @throws  MissException
     */

    //  http://www.moocminiprogram.com/api/v1/banner/1
    public function getBanner($id)
    {
        //  9/0; // test  ExceptionHandler.php
        (new IDMustBePositiveIntValidate())->goCheck();

        $banner = BannerModel::getBannerById($id);
//        var_dump($banner);
        if (!$banner) {
            throw new MissException([
                'msg' => '请求banner不存在',
                'errorCode' => 40000
            ]);
        }
        return $banner->toArray();
    }
}